<template>
  <a-modal
    title="文件预览"
    :width="640"
    :visible="visible"
    @ok="handleOk"
    @cancel="handleCancel">
    <pre v-if="!isImage">{{ initData.view_url }}</pre>
    <img
      v-else
      :alt="initData.origin_name"
      style="width: 100%"
      :src="initData.view_url" />
  </a-modal>
</template>

<script>
export default {
  data () {
    return {
      visible: false,
      isImage: false,
      initData: {}
    }
  },
  computed: {
  },
  methods: {
    open (record) {
      this.initData = record
      const imageExtArr = ['jpeg', 'jpg', 'bmp', 'png', 'gif']
      this.isImage = imageExtArr.indexOf(this.initData.file_ext) !== -1
      this.visible = true
    },
    handleOk (e) {
      this.visible = false
    },
    handleCancel () {
      this.visible = false
    }
  }
}
</script>
